 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */
 package cn;

 import cn.shun.config.SpringConfig;
 import cn.shun.entity.Emp;
 import cn.shun.mapper.DbMapper;
 import cn.shun.mapper.EmpMapper;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

 import java.time.LocalDate;
 import java.util.HashMap;
 import java.util.Map;

 /**
  * <p>Project: MyBatis2023 - Demo
  * <p>Powered by yishun On 2023-01-20 17:41:05
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 @SpringJUnitConfig(SpringConfig.class)
 public class Demo {
     @Autowired
     EmpMapper em;

     @Autowired
     DbMapper dm;
     @Test
     @DisplayName("emp 删除数据")
     void delete() {
         int i = em.deleteById(19);
         if (i > 0) {
             System.out.println("删除成功");
         }
     }

     @Test
     @DisplayName("emp 批量删除数据int[]")
     void deleteByIds() {
         int i = em.deleteByIds(new int[]{19, 17, 16});
         if (i > 0) {
             System.out.println("删除成功");
         }
     }

     @Test
     @DisplayName("emp 批量删除数据map")
     void deleteByIdss() {
         Map<String, Object> map = new HashMap<>();
         map.put("id", 6);
         map.clear();
         map.put("ids", new int[]{17, 18, 19});
         int i = em.deleteByIdss(map);
         if (i > 0) {
             System.out.println("删除成功");
         }
     }

     @Test
     @DisplayName("emp 插入数据")
     void insert() {
         int i = em.add("Now", 28, "Java工程师", 8000, LocalDate.of(2023, 01, 20), 2, 2);
         if (i > 0) {
             System.out.println("数据插入成功");
         }
         System.out.println("============================");
         select();
     }

     @Test
     @DisplayName("emp 插入数据 Emp")
     void empSave() {
         Emp emp = new Emp();
         emp.setName("tonny");
         emp.setJob("实习生");
         emp.setEntrydate(LocalDate.now());
         int i = em.empSave(emp);
         if (i > 0) {
             System.out.println("数据插入成功");
         }
         System.out.println("============================");
         select();
     }

     @Test
     @DisplayName("emp 插入数据")
     void insertD() {
         Map<String, Object> map = new HashMap<>();
         map.put("name", "王某");
         map.put("age", 23);
         map.put("job", "C++工程师");
         map.put("salary", 2000);
         map.put("entrydate", LocalDate.of(2023, 02, 13));
         int i = em.insert(map);
         if (i > 0) {
             System.out.println("数据插入成功");
         }
         System.out.println("============================");
         select();
     }

     @Test
     @DisplayName("emp 查询数据")
     void select() {
         for (Map<String, Object> m : em.query()) {
             System.out.println(m.get("id") + "==>" + m.get("name") + "==>" + m.get("job"));

         }
     }

     @Test
     @DisplayName("emp 根据id查询")
     void queryById() {
         Emp e = em.queryById(15);
         System.out.println(e.getName());
     }

     @Test
     @DisplayName("emp 根据id修改")
     void update() {
         Emp e=em.queryById(20);
         e.setName("jack");
         int i=em.update(e);
         if(i>0){
             System.out.println("修改成功");
         }
     }
     @Test
     @DisplayName("emp 根据id修改动态sql")
     void update01() {
         Map<String,Object> map=new HashMap<>();
         map.put("id",20);
         map.put("name","tommy");
         int i=em.update(map);
         if(i>0){
             System.out.println("修改成功");
         }
     }
     @Test
     @DisplayName("emp 修改全部年龄")
     void updateAllAge() {

         int i=em.updates(1);
         if(i>0){
             System.out.println("修改成功");
         }
     }
     @Test
     @DisplayName("emp 查询")
     void selectList() {

         System.out.println(em.selectList());
     }
     @Test
     @DisplayName("emp 查询")
     void selectListMap() {
         System.out.println(em.selectListMap());

     }
     @Test
     @DisplayName("emp count")
     void count() {
         System.out.println(em.count());

     }
     @Test
     @DisplayName("emp count")
     void  maxAge() {
         System.out.println(em.maxAge());

     }


     @Test
     @DisplayName("emp tableCount")
     void  countTable() {
         System.out.println(dm.count("dbtest.emp"));//17
     }

     @Test
     @DisplayName("创建数据库")
     void  createDb() {
         dm.creatDb("mybatisdb2023");
     }


 }
